/**
 * KafkaProducerOperatorMain.java
 *
 * @author: ZhuJiahui
 * @date: 2019/1/11 20:40
 */
package com.zhujiahui.kafka.first;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 参考http://blog.51cto.com/xpleaf/2090936
 *
 * @description: 向Kafka topic中生产相关的数据
 * @author: ZhuJiahui
 * @version: 1.0
 */
public class KafkaProducerOperatorMain {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        InputStream in = KafkaProducerOperatorMain.class.getClassLoader()
                .getResourceAsStream("producer.properties");
        properties.load(in);

        Producer<String, String> producer =
                new KafkaProducer<>(properties);
        String topic = properties.getProperty("producer.topic");

        String key = "zhujiahui";
        String value = "zhujiahui value";

        ProducerRecord<String, String> producerRecord =
                new ProducerRecord<>(topic, key, value);
        producer.send(producerRecord);
        producer.close();

    }
}
